package com.acegear.horizon.domain.services;

import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by wangsike on 2017/3/2.
 */
@Service
public class PictureService {

    @Value("${horizon.server}")
    private String horizonServer;

    @Value("${replaceImage.management}")
    public String managementImage;

    @Value("${replaceImage.client}")
    public String clientImage;


    public String transAvatar(String from, Long userId) {
        String path = horizonServer + "/pic/images/trans";
        try {
            JsonNode jsonNode = Unirest
                    .post(path)
                    .field("from", from)
                    .field("userId", userId)
                    .asJson()
                    .getBody();
//            return jsonNode.getObject().getJSONObject("body").getString("url"); // TreeJohn 编译报错
            return "";
        } catch (UnirestException e) {
            e.printStackTrace();
            return "";
        }
    }

    public String imageInfo(String url) {
        try {
            return Unirest.get(url.replace("https", "http").replaceAll("/*w700\\S*", "") + "?imageInfo")
                    .asJson().getBody().toString();
        } catch (UnirestException e) {
            e.printStackTrace();
            return null;
        }
    }



}